package com.simple.core.util;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.IdUtil;

/**
 * @author : mocun
 * @since : 2023/3/11
 */

public final class SnowFlakeUtils {

    /**
     * 默认数据中心id
     */
    private static final long DEFAULT_DATACENTER_ID = 1L;

    public static long nextId() {
        // 最多支持32个节点
        long workerId = NetUtil.ipv4ToLong(NetUtil.getLocalhostStr()) % 32;
        return IdUtil.getSnowflake(workerId, DEFAULT_DATACENTER_ID).nextId();
    }

}
